<template>
  <div v-if="partListCon">
    <!-- {{ activeBnnerIndex }} -->
    <!-- {{ partListCon }} -->
    <el-form ref="form" :model="partListCon" label-width="110px" size="small">
      <el-form-item label="是否显示">
        <el-switch
          class="zdySwith"
          :width="82"
          :value="partListCon.show"
          active-color="#13ce66"
          @change="updateInput($event, 'show')"
          inactive-color="#ffffff"
          active-text="显示"
          inactive-text="隐藏"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>

      <el-form-item label="标题">
        <el-input
          @input="updateInput($event, 'title')"
          :value="partListCon.title"
          placeholder="请输入标题"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="副标题">
        <el-input
          @input="updateInput($event, 'title_en')"
          :value="partListCon.title_en"
          placeholder="请输入副标题"
        >
        </el-input>
      </el-form-item>
      <!-- <el-form-item label="链接到">
        <el-col :span="16">
          <el-input :value="partListCon.links" @input="updateInput($event, 'links')" class="mar-input"></el-input>
          <el-input :value="partListCon.desc" @input="updateInput($event, 'desc')"></el-input>
        </el-col>
        <el-col :span="6" class="mar_lf_15">
          <LinkMenu @sendRow="getSendRow($event)" :index="0"></LinkMenu>
        </el-col>
      </el-form-item> -->
      <el-form-item
        label="展示模式"
        v-show="partListCon.links == 'product' || partListCon.links == 'tour'"
      >
        <el-select
          v-model="partListCon.style"
          placeholder="请选择"
          @change="updateInput($event, 'style')"
        >
          <el-option
            v-for="(item, i) in style_option"
            :key="i"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品类型">
        <el-select
          v-model="partListCon.links"
          placeholder="请选择"
          @change="updateInput($event, 'links')"
        >
          <el-option
            v-for="(val, key, i) in menulist"
            :key="i"
            :label="val"
            :value="key"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-divider></el-divider>

      <el-form-item
        label="选择商品"
        v-show="partListCon.links != '' && partListCon.links != 'together'"
        style="padding-bottom: 50px"
      >
        <div class="xzshop">
          <div class="xzshopitem">
            <div
              class="index_img_nav img_nav addImg_menu"
              @click.prevent="showDio"
            >
              <i class="el-icon-plus"></i>
            </div>
          </div>
          <div
            class="xzshopitem"
            v-for="(item, index) in partListCon.banner"
            :key="index"
          >
            <div class="index_img_nav img_nav">
              <img
                :src="$fnc.getImgUrl(item.piclink)"
                alt
                v-if="item.piclink"
              />
              <img
                :src="$fnc.getImgUrl(item.avatar)"
                alt
                v-else-if="item.avatar"
              />
            </div>

            <div class="sortshop_box">
              <div>
                <i
                  class="el-icon-caret-left"
                  @click="toCheckArrIndex(index, 'up')"
                ></i>
                <i
                  class="el-icon-caret-right"
                  @click="toCheckArrIndex(index, 'down')"
                ></i>
              </div>
            </div>

            <a
              href="javascript:;"
              @click.prevent="delshopitem(item, index)"
              class="alert-delete dele_banner"
              title="隐藏"
            >
              <i class="el-icon-error"></i>
            </a>
          </div>
        </div>
        <!-- <el-row class="items" :gutter="24">
          <el-col :span="6" class="tr">
            <div class="index_img_nav img_nav addImg_menu" @click.prevent="showDio" style="margin:0 auto">
              <i class="el-icon-plus"></i>
            </div>
          </el-col>
          <el-col :span="6" class="tr shops_list" v-for="(item, index) in partListCon.banner" :key="index">
            <div class="index_img_nav img_nav">
              <img :src="$fnc.getImgUrl(item.piclink)" alt />
            </div>
            <div class="sel_img_btn sel_img_btn-shop" style="height:auto">
              <el-input :value="index" type="number"></el-input>
            </div>
            <a href="javascript:;" @click.prevent="delData(index)" class="alert-delete dele_banner" title="隐藏">
              <i class="el-icon-close"></i>
            </a>
          </el-col>
        </el-row> -->
      </el-form-item>
    </el-form>

    <el-dialog
      title="选择商品"
      @close="closeshow"
      :lock-scroll="true"
      :append-to-body="true"
      :visible.sync="show"
      width="1200px"
      style="padding: 20px"
    >
      <xzShop
        :types="partListCon.links"
        :show="xzshow"
        @isshow="closeshow"
        @sendShop="setId"
        :data="list.data"
        :isAddIden="false"
      ></xzShop>
    </el-dialog>

    <el-dialog
      title="选择音频课程"
      @close="closeshow"
      :lock-scroll="true"
      :append-to-body="true"
      :visible.sync="audio_show"
      width="1200px"
      style="padding: 20px"
    >
      <xzBook
        :types="partListCon.links"
        :show="xzshow"
        @isshow="closeshow"
        @sendBook="setBook"
        :isAddIden="false"
      ></xzBook>
    </el-dialog>

    <el-dialog
      title="选择人物"
      @close="closeshow"
      :lock-scroll="true"
      :append-to-body="true"
      :visible.sync="character_show"
      width="1200px"
      style="padding: 20px"
    >
      <xzCharacter
        :types="partListCon.links"
        :show="xzshow"
        @isshow="closeshow"
        @sendCharacter="setBook"
        :isAddIden="false"
      ></xzCharacter>
    </el-dialog>
  </div>
</template>

<script>
import uploadpic from "@/components/page/pic/up_pic";
import LinkMenu from "@/components/currency/Link_menu.vue";
import xzShop from "@/components/page/module/module_select/selshopbox";
import xzBook from "@/components/page/book/audio_select.vue";
import xzCharacter from "@/components/page/module/module_select/selCharacter";
import { mapState, mapGetters } from "vuex";
export default {
  data() {
    return {
      xzshow: false,
      currentPage1: 1,
      pageSize: 10,
      show: false,
      list: {
        data: [],
      },

      style_option: [
        {
          label: "一行2个",
          value: "0",
        },
        {
          label: "一行1个",
          value: "1",
        },
        {
          label: "大图显示",
          value: "2",
        },
      ],
      audio_show: false,
      character_show: false,
    };
  },

  computed: {
    ...mapGetters(["partListConConss"]),
    ...mapState({
      active: (state) => state.modulePage.active,
      activeBnnerIndex: (state) => state.modulePage.bannerNowIndex,
      allbanner: (state) => state.modulePage.allbanner,
      menulist: (state) => state.modulePage.menulist,
    }),
    partListCon() {
      if (this.activeBnnerIndex >= 0) {
        return this.allbanner[this.activeBnnerIndex];
      } else {
        return {};
      }
    },
  },
  components: {
    uploadpic,
    LinkMenu,
    xzShop,
    xzBook,
    xzCharacter,
  },
  created() {},
  mounted() {},
  methods: {
    toCheckArrIndex(i, status) {
      console.log(11);
      //排序
      var index2 = "";
      if (status == "up") {
        index2 = i - 1;
      } else {
        index2 = i + 1;
      }
      this.$store.commit("sortbanner_son", {
        key: this.activeBnnerIndex,
        index1: i,
        index2: index2,
        status: status,
      });
    },
    sortshop(val, i, name) {
      console.log(11);
      this.$store.commit("set_sonbanner_item", {
        key: this.activeBnnerIndex,
        name: name,
        index: i,
        val: val,
      });
    },
    delshopitem(item, index) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: index,
      });
      var val = this.partListCon.text.replace(item.id + "@", "");

      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val,
      });
    },
    closeshow() {
      this.show = false;
      this.xzshow = false;
      this.audio_show = false;
      this.character_show = false;
      // setTimeout(() => {
      //   this.show = false;
      // }, 100);
    },
    setId(row) {
      // this.show = false;
      // this.xzshow = false;
      // console.log(row);
      var val = this.partListCon.text + row.id + "@";
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val,
      });
      // console.log("aaaaaaaaaaaaaaaaaaa",this.partListCon.text);
      // this.$store.commit("addbanner_shopitem", {
      //   title: row.title,
      //   piclink: row.piclink
      // });
      this.$store.commit("addbanner_shopitem", row);
    },
    setBook(row) {
      // 选择课程
      var val = this.partListCon.text + row.id + "@";
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val,
      });
      this.$store.commit("addbanner_shopitem", row);
    },
    showDio() {
      if (
        this.partListCon.links == "audio" ||
        this.partListCon.links == "fiction"
      ) {
        this.audio_show = true;
      } else if (this.partListCon.links == "character") {
        this.character_show = true;
      } else {
        this.show = true;
      }
      setTimeout(() => {
        this.xzshow = true;
      }, 100);
      console.log("iiiiiiiiiiiiii:", this.partListCon.links);
    },
    del_banneritem(i) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: i,
      });
    },
    set_banneritem_val(pic, i, name) {
      this.$store.commit("set_sonbanner_item", {
        key: this.activeBnnerIndex,
        name: name,
        index: i,
        val: pic,
      });
    },

    updateInput(val, name) {
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: name,
        val: val,
      });
      if (name == "links") {
        // 切换商品类型,全部商品清空
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "text",
          val: "",
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "banner",
          val: [],
        });
      }
    },

    getSendRow(row) {
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      var result = this.$fnc.getSendRow(row);
      var obj = {};
      obj.key = this.activeBnnerIndex;
      console.log(result);
      if (result.title != "自定义链接") {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: result.desc,
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: result.links,
        });
      } else {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: "自定义链接",
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: " ",
        });
      }
    },
  },
  watch: {},
};
</script>

<style scoped lang="less"></style>
